<?php
namespace Admin\Controller;
use Admin\Controller\CheckController;
use Admin\Controller\ApplyController;
class InsideController extends AdminController{
	//内勤审核管理
    protected function _initialize() {
		parent::_initialize ();
	}

	public function index(){
		$this->display();
	}

	//审核列表
	public function check(){
		$where = '1 = 1';
		if(I('get.aid', -1, 'intval') <> -1)
		{
			if(I('get.aid', -1, 'intval')==0){
				$where .=' and  aid =0';
			}else{
				$where .=' and aid='.I('get.aid', 0, 'intval');
			}
		}
		$where .= I('get.user_name') != '' ? ' and user_name like "%'.I('get.user_name').'%"' : '';

		$where .= I('get.telephone') != '' ? ' and telephone = '.I('get.telephone') : '';

		$where .= I('get.create_time_beg') != '' ? ' and create_time >= '.strtotime(I('get.create_time_beg')) : '';

		$where .= I('get.create_time_end') != '' ? ' and create_time < '.strtotime(I('get.create_time_end')) : '';
        $where .= I('get.status') !='' ? ' and u.status='.I('get.status') : ' and (u.status = 1 or u.status = 9)';
        if(session('adminInfo.gpid')!=0){
           $groupInfo=$this->getInfo('*','group','id='.session('adminInfo.gpid'));
		    if($groupInfo['work_status']==1){
		       $where.=' and gpid='.session('adminInfo.gpid');
		    }
        }

        $where.=' and check_status=0';

        $list=$this->getList('u.*,b.bank_short_name','user u',$where,'id desc',true,'app_bank b on u.loan_bank_id=b.id');
		 foreach ($list as $key => $value) {
			$group=$this->getInfo('*','group','id='.$value['gpid']);
			$list[$key]['group_name']=$group['name'];
		}
		$this->assign('list', $list);
		$this->display();
	}

	//内勤审核
	public function checkApply()
	{
		$id=I('get.user_id',0,'intval');
		$detail=new ApplyController();
        $detail->get_info($id);
        $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

		$src =[];

		$pics = '';
		foreach($userFiles as $k3)
		{
			$dist  = $k3['file_dist'];
			$src[] = $dist;

			$pics.= "'".$k3['file_dist']."',";

		}
		$this->assign('src',$pics);
        $this->assign('userFiles',$userFiles);
		$this->display();
	}

    //设置为正在审核状态
	public function setCheck_status(){
		$info=$this->getInfo('*','user',' check_status='.$_POST['Cstatus'].' and check_admin_id='.session('adminInfo.id').' and status=101');
		if($info){
          echo '还有未完成的操作';
          exit;
		}
		$result=M('user')->where('id='.$_POST['id'].' and check_status='.$_POST['Cstatus'])->setField('status',101);
		if($result){
			 M('user')->where('id='.$_POST['id'])->setField('check_admin_id',session('adminInfo.id'));
             $this->ajaxReturn(array('info'=>'操作状态设置成功','status'=>1));
		}else{
              $this->ajaxReturn(array('info'=>'该申请正在操作中,或不在当前审核下','status'=>0));
			 // echo '参数错误,该申请不在当前的审核下';
			 // exit;
		}

	}
  //垫资审核状态
	public function setMatApply_status(){
		$info=$this->getInfo('*','user u','check_admin_id='.session('adminInfo.id').' and check_status>=6 and u.status=101 ');
//		print_r($info);die;
		if($info){
          echo '还有未审核完的申请';
          exit;
		}
		$matApply=$this->getInfo('*','advance','user_id='.$_POST['id']);
		//$matApply=$this->getInfo('*','advance','user_id='.$_POST['id'].' and status='.$_POST['matStatus']);
		if(!$matApply || $matApply['status']==0){
			//$data=array('status'=>101,'check_admin_id'=>session('adminInfo.id'));
            $result=M('user')->where('id='.$_POST['id'])->setField('status',101);
			if($result){
				 M('user')->where('id='.$_POST['id'])->setField('check_admin_id',session('adminInfo.id'));
	             $this->ajaxReturn(array('info'=>'操作状态设置成功','status'=>1));
			}else{
	             $this->ajaxReturn(array('info'=>'该申请正在操作中,或不在当前审核下','status'=>0));
			}
		}else{
           $this->ajaxReturn(array('info'=>'该垫资申请已添加','status'=>0));
		}

	}

	 //垫资状态操作
	public function setMatApply_Info(){
		$info=$this->getInfo('*','user','check_admin_id='.session('adminInfo.id').' and check_status>=6 and status=101');
		if($info){
          echo '还有未审核完的申请';
          exit;
		}
		$matApply=$this->getInfo('*','advance','user_id='.$_POST['id'].' and status='.$_POST['matStatus']);
		if($matApply){
            $result=M('user')->where('id='.$_POST['id'])->setField('status',101);
			if($result){
				 $result=M('user')->where('id='.$_POST['id'])->setField('check_admin_id',session('adminInfo.id'));
	             $this->ajaxReturn(array('info'=>'操作状态设置成功','status'=>1));
			}else{
	              $this->ajaxReturn(array('info'=>'该申请正在操作中,或不在当前审核下','status'=>0));
			}
		}else{
           $this->ajaxReturn(array('info'=>'正在操作中,不在当前审核下','status'=>0));
		}

	}

}